package com.cn.springcloudshop.service.impl;

import com.cn.springcloudshop.mapper.YmShopCatMapper;
import com.cn.springcloudshop.model.YmShopCat;
import com.cn.springcloudshop.model.YmShopCatExample;
import com.cn.springcloudshop.model.YmShopCatPOJO;
import com.cn.springcloudshop.service.inter.CatService;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import java.util.Date;
import java.util.List;

/**
 * @Author: wuyanzu
 * @Date: 2018/8/13
 */
@Service("catService")
@Transactional(rollbackFor = Exception.class)
public class CatServiceImpl implements CatService {

    @Autowired
    private YmShopCatMapper ymShopCatMapper;

    @Override
    public int countByExample(YmShopCatExample example) {
        Assert.notNull(example, "类目查询条件不能为空");
        Integer res = ymShopCatMapper.countByExample(example);
        return res == null ? 0 : res;
    }

    @Override
    public int deleteByExample(YmShopCatExample example) {
        return 0;
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        Assert.notNull(id,"类目ID不能为空");
        Integer res = ymShopCatMapper.deleteByPrimaryKey(id);
        return res == null ? 0 : res;
    }

    @Override
    public int insert(YmShopCat record) {
        Assert.notNull(record, "类目不能为空");
        record.setCreated(new Date());
        Integer res = ymShopCatMapper.insert(record);
        return res == null ? 0 : res;
    }

    @Override
    public int insertSelective(YmShopCat record) {
        Assert.notNull(record, "类目不能为空");
        record.setCreated(new Date());
        Integer res = ymShopCatMapper.insertSelective(record);
        return res == null ? 0 : res;
    }

    @Override
    public List<YmShopCat> selectByExample(YmShopCatExample example) {
        Assert.notNull(example, "查询实例不能为空");
        return ymShopCatMapper.selectByExample(example);
    }

    @Override
    public YmShopCat selectByPrimaryKey(Long id) {
        Assert.notNull(id, "类目id不能为空");
        return ymShopCatMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(YmShopCat record) {
        Assert.notNull(record, "商品类目不能为空");
        record.setUpdated(new Date());
        Integer res = ymShopCatMapper.updateByPrimaryKeySelective(record);
        return res == null ? 0 : res;
    }

    @Override
    public int updateByPrimaryKey(YmShopCat record) {
        return 0;
    }

    @Override
    public int deleteBatchByPK(List<Long> ids, Integer status) {
        Assert.notEmpty(ids, "类目ID不能为空");
        Assert.notNull(status, "类目状态不能为空");
        Integer res = ymShopCatMapper.deleteBatchByPK(ids, status);
        return res == null ? 0 : res;
    }

    @Override
    public List<YmShopCatPOJO> findCatByParentId(Long parentid) {
        Assert.notNull(parentid, "父类id不能为空");
        return ymShopCatMapper.findCatByParentId(parentid);
    }
}
